package com.ysd.twocrm.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.mapper.Mapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ysd.twocrm.entity.Student;
import com.ysd.twocrm.entity.StudentClass;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Set;

public interface StudentClassMapper extends BaseMapper<StudentClass> {

     //查询全部系别
    @Select(value = "select stuclassdepartment from studentclass")
    Set<String> getAllDepartment();
    //根据系别来查询专业
    @Select(value = "select stuClassSpecialty from studentclass where stuclassdepartment=#{stuClassDepartment}")
    Set<String> getAllSpecialty(String stuClassDepartment);
    //根据专业来查询班级
    @Select(value = "select * from studentclass where stuClassSpecialty=#{stuClassSpecialty}")
    List<StudentClass> getAllStuClass(String stuClassSpecialty);
    ////多条件分页查询班级
    <E extends IPage<StudentClass>> E findStuClass(E page, @Param("ew") Wrapper<StudentClass> queryWrapper);
    //根据班级来查询判断班级是否存在
    @Select(value = "select * from studentclass where stuClass=#{stuClass}")
    StudentClass findIfStudentClass(String stuClass);
    //根据班级id来修改数量，每次添加学生的时候就为这个班级添加一个数量
    @Update(value = "update studentclass set stuclasssum=stuclasssum+1 where stuclassid=#{stuclassId}")
    Integer exitStudentClassByIdSum(Integer stuclassId);
    //根据班级id来修改数量，每次修改学生的时候就为原先的这个班级去掉一个数量
    @Update(value = "update studentclass set stuclasssum=stuclasssum-1 where stuclassid=#{stuclassId}")
    Integer exitStudentClassByIdOutSum(Integer stuclassId);
    //根据用户的id来将他修改为空，因为用户去除了这个辅导员，所以也要删除
    @Update(value = "update studentclass set stuClassIstId=0 where stuClassIstId=#{stuClassIstId}")
    Integer exitStudentClassByIstId(Integer stuClassIstId);

    //根据用户的id来将他修改为空，因为用户去除了这个教员，所以也要删除
    @Update(value = "update studentclass set stuClassTeaId=0 where stuClassIstId=#{stuClassTeaId}")
    Integer exitStudentClassByTeaId(Integer stuClassTeaId);
}
